$(function(){
	var t=0;
	if(t==null || t==0){
		var waterflow = $("#waterflow");
		waterflow.masonry({
			itemSelector:'.content-list-water',
			isFitWidth:true
		});
	}else{
		$(".content-list-water").removeClass("content-list-water").addClass("content-list");
	}
	
	windowScroll();
});
function changeWater(isWater){
	if(isWater==0){
		if(location.href.indexOf("?t=1")>0){
			location=location.href.replace("?t=1","");
		}else{
			location = location;
		}
	}else{
		if(location.href.indexOf("?t=1")<0){
			location=location+"?t=1";
		}else{
			location = location;
		}
	}
}

function windowScroll(){
	$(window).scroll(function(){
		if(($(document).height() - $(window).height() - $(document).scrollTop())<10){
			getNewDatabases();
		}
	});
}

function getNewDatabases(){
	var typeid = $(":input[name='typeid']");
	var page = $(":input[name='page']");
	var pageSize = $(":input[name='pageSize']");
	
	var hasContent = $(":input[name='hasContent']");
	
	var pageNum = parseInt(page.val())+1;
	if(hasContent.val()==="true"){
		var not_water_flow = $("#not-water-flow");
		$.get("database_finds.jspx?format=json",{typeid:typeid.val(),page:pageNum,pageSize:pageSize.val()},function(data){
			page.val(pageNum);
			hasContent.val(data.hasContent);
			var databases = data.databases;
			if(databases!=null){
				var content = template("content-list-template",{databases:databases});
				not_water_flow.append(content);
			}
		});
	}
}

